﻿using System;
using System.Collections.Generic;
using System.Text;

/*
 * Author:Conis
 * Date:
 * Description:JSON的数组节点
 */

namespace Coins.Squirrel.Nodous.JSON
{
    public class JSONNodousItem : JSONNodousComponent, INodousItem
    {
        #region 其它方法
        /// <summary>
        /// 创建一个数组节点
        /// </summary>
        /// <param name="name">节点名称</param>
        protected internal JSONNodousItem(string name)
            : base(name, string.Empty) { }

        /// <summary>
        /// 创建前缀
        /// </summary>
        protected override void CreatePreifx()
        {
            this.container.Append(this.name).Append(":");
            this.container.Append("[");
        }

        /// <summary>
        /// 创建后缀
        /// </summary>
        protected override void CreateSuffix()
        {
            this.container.Append("]");
            //如果当前节点不是最后一个节点，则加上逗号
            if (this.currentIndex != this.brotherCount)
            {
                this.container.Append(",");
            }
        }
        #endregion

        #region INodousItem 成员
        /// <summary>
        /// 添加数组节点
        /// </summary>
        /// <param name="name">节点名称</param>
        /// <returns></returns>
        public INodousNode AddItemNode()
        {
            JSONNodousItemNode node = new JSONNodousItemNode();
            node.Parent = this;
            this.Add(node);
            node.Parent = this;
            return node;
        }

        #endregion
    }
}
